package com.ll.SchoolSafe.Controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ll.SchoolSafe.Service.ClassService;
import com.ll.SchoolSafe.Service.ScoreService;
import com.ll.SchoolSafe.Service.StudentService;
import com.ll.SchoolSafe.pojo.Classes;
import com.ll.SchoolSafe.pojo.CommonResult;
import com.ll.SchoolSafe.pojo.Score;
import com.ll.SchoolSafe.pojo.Student;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "学生档案")
@RequestMapping("/studentArchives")
public class StudentArchivesController {
    @Autowired
    private ClassService classService;
    @Autowired
    private StudentService studentService;
    @Autowired
    private ScoreService scoreService;

    /**
     * 获取所有班级
     * @return
     */
    @ApiOperation("获取所有班级")
    @GetMapping("/getAllClass")
    public CommonResult getAllClass(){
        List<Classes> list= classService.getAllClass();
        return new CommonResult(200,"获取所有班级成功",list);
    }

    /**
     * 获取班级下所有学生
     * @param classId
     * @return
     */
    @ApiOperation("获取班级下所有学生")
    @GetMapping("/getAllStudentByClassId/{classId}")
    public CommonResult getAllStudentByClassId(@PathVariable Integer classId){
        List<Student> list= studentService.list(
                new QueryWrapper<Student>().eq("class_id", classId)
        );
        return new CommonResult(200,"获取班级下所有学生成功",list);
    }

    /**
     * 获取单独学生档案
     * @param studentId
     * @return
     */
    @ApiOperation("获取学生档案")
    @GetMapping("/getStudentArchives/{studentId}")
    public CommonResult getStudentArchives(@PathVariable Integer studentId){
        Student student= studentService.getStudentArchives(studentId);
        return new CommonResult(200,"获取学生档案成功",student);
    }

    /**
     * 根据studentId获取成绩单
     * @param studentId
     * @return
     */
    @ApiOperation("根据studentId获取成绩单")
    @GetMapping("/getScoreByStudentId/{studentId}")
    public CommonResult getScoreByStudentId(@PathVariable Integer studentId){
        Score byId = scoreService.getScoreByStudentId(studentId);
        return new CommonResult(200,"获取成绩单成功",byId);
    }

}
